package cn.jkgly.utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet(name = "wxAuthorization", urlPatterns = "/wxAuthorization")
public class wxAuthorization extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String backUrl = "http://auth.jkgly.cn/callBack";
        String url = "https://open.weixin.qq.com/connect/oauth2/authorize" +
                "?appid=" + AuthUtil.APPID +
                "&redirect_uri=" + URLEncoder.encode(backUrl) +
                "&response_type=code" +//固定code
                "&scope=snsapi_userinfo" +//snsapi_base(只返回openid),snsapi_userinfo
                "&state=state" +//用户自定义
                "#wechat_redirect";//锚点
        resp.sendRedirect(url);
    }

}
